<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ include file="/include/header.jsp"%>
<!-- 加载树-->
<%@ include file="/include/zTree.jsp"%>
<script type="text/javascript">
	var currKeMuFenLei;
	var defaultSetting = {
		data : {
			simpleData : {
				enable : true
			}
		}, view : {
			selectedMulti : false
		}

	};
	function searchByLb (leiBieValue) {
		$.post("${ctx}/dickm/mgr?ts=" + new Date().getTime()+"&leiBie="+leiBieValue, function (data) {
			$("#kmTree").html("");
			$.fn.zTree.init($("#kmTree"), defaultSetting, data);
			
			//全部节点都要展开
			var treeObj = $.fn.zTree.getZTreeObj("kmTree");
			treeObj.expandAll(true);
		});
	}
	function search () {
		searchByLb (currKeMuFenLei);
	}
	
</script>
</head>
<body>
	<div class="main_panel">
		<div class="ch_panel" id="queryDiv" style="margin-bottom: 5px;">
			<input type="hidden" data-qname="CSRFToken" value="${csrfToken}"/>
			<table>
				<tr>
					<td class="c_table">
						<input type="button" value="资产" id="zcBtn" data_value="ZC" class="e_btn" style="margin-right: 5px;" />
						<input type="button" value="负债" id="fzBtn" data_value="FZ" class="e_btn" style="margin-right: 5px;" />
						<input type="button" value="权益" id="qyBtn" data_value="QY" class="e_btn" style="margin-right: 5px;" />
						<input type="button" value="成本" id="cbBtn" data_value="CB" class="e_btn" style="margin-right: 5px;" />
						<input type="button" value="损益" id="syBtn" data_value="SY" class="e_btn" style="margin-right: 5px;" />
					</td>
				</tr>
			</table>
		</div>
		<div class="ch_panel" id="queryDiv2" style="height: 90%; overflow: auto;">
			<input type="hidden" data-qname="CSRFToken" alue="${csrfToken}"/>
			<div class="r_action">
				<input type="button" class="save_btn" value="新增" id="addBtn" />
				<input type="button" class="save_btn" value="修改" id="editBtn" />
				<input type="button" class="save_btn" value="删除" id="deleteBtn" />
				<input type="button" class="save_btn" value="查看" id="viewBtn" />
			</div>
			<div id="kmTree" class="ztree" style="background-color: white;"></div>
		</div>
	</div>
	
	<script type="text/javascript">
	
		$(function () {

			// 1、资产
			$("#zcBtn").click(function () {
				onclickBtn(this);
				searchByLb($(this).attr("data_value"));
			});
			// 2、负债
			$("#fzBtn").click(function () {
				onclickBtn(this);
				searchByLb($(this).attr("data_value"));
			});
			// 3、权益
			$("#qyBtn").click(function () {
				onclickBtn(this);
				searchByLb($(this).attr("data_value"));
			});
			// 4、成本
			$("#cbBtn").click(function () {
				onclickBtn(this);
				searchByLb($(this).attr("data_value"));
			});
			// 5、损益
			$("#syBtn").click(function () {
				onclickBtn(this);
				searchByLb($(this).attr("data_value"));
			});

			$("#zcBtn").click();

		});

		function onclickBtn (thiss) {
			
			currKeMuFenLei = $(thiss).attr("data_value");
			
			$(".c_table :button").removeClass("f_btn");
			$(".c_table :button").removeClass("e_btn");
			$(".c_table :button").addClass("e_btn");

			$(thiss).removeClass("e_btn");
			$(thiss).removeClass("f_btn");
			$(thiss).addClass("f_btn");
		}
		
	</script>
	
	
	<script type="text/javascript">
		// 获取选中节点的ID
		function getSelectedNodeId () {
			var treeObj = $.fn.zTree.getZTreeObj("kmTree");
			var nodes = treeObj.getSelectedNodes();
			if (nodes.length != 1) {
				alert("请选择一个节点！");
				return false;
			}
			return nodes[0].id;
		}
		
		function getSelectedNodeId2 () {
			var treeObj = $.fn.zTree.getZTreeObj("kmTree");
			var nodes = treeObj.getSelectedNodes();
			if (nodes.length != 1) {
				return false;
			}
			return nodes[0].id;
		}

		$(function () {
			// 1、添加
			$("#addBtn").click(function () {
				var parentId = getSelectedNodeId2();
				parent.member_add("新增科目类别", "${ctx}/dickm/toAdd?parentId="+parentId+"&currKeMuFenLei="+currKeMuFenLei, 760, 300);
			});

			// 2、详细
			$("#viewBtn").click(function () {
				// 2.1 弹窗窗口，显示详细信息
				seajs.use("component/dialog", function (dialog) {
					var uuid = getSelectedNodeId();
					if (uuid == "") {
						return;
					}
					parent.member_add("查看科目类别", "${ctx}/dickm/view?uuid=" + uuid, 760, 300);
				});
			});

			// 3、编辑
			$("#editBtn").click(function () {
				// 3.1 弹窗窗口，显示详细信息
				var uuid = getSelectedNodeId();
				//获取主键
				if (uuid == "") {
					return;
				}
				parent.member_add("修改科目类别", "${ctx}/dickm/toEdit?uuid=" + uuid, 760, 300);
			});

			// 4、删除
			$("#deleteBtn").click(function () {
				var uuid = getSelectedNodeId();
				if (uuid == "") {
					return;
				}
				if (confirm('删除该节点的同时会将其下辖节点也一并删除,确定删除？')) {
					$.post("${ctx}/dickm/delete", {
						uuid : uuid, CSRFToken : $("#CSRFToken").val()
					}, function (result) {
						if ("succ" == result) {
							alert("操作成功");
							// 刷新列表页面
							searchByLb (currKeMuFenLei);
						} else {
							alert(result);
						}
					}, "json");
				}

			});

		});
	</script>

</body>
</html>